package com.casic.kafka.listener;

import org.apache.kafka.clients.producer.RecordMetadata;
import org.springframework.kafka.support.ProducerListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * kafka消息推送结果监听
 * @author 朵朵
 *
 */
@Slf4j
@Component
public class KafkaSendResultHandler implements ProducerListener {

	@Override
	public void onSuccess(String topic, Integer partition, Object key, Object value, RecordMetadata recordMetadata) {
		log.info(String.format("成功：\n \t 主题:%s,对应目标分区：%s,结果：%s",topic,partition,recordMetadata.toString() ));
	}

	@Override
	public void onError(String topic, Integer partition, Object key, Object value, Exception exception) {
		log.info(String.format("失败：\n \t 主题:%s,对应目标分区：%s,结果：%s",topic,partition,exception.toString() ));
	}

	@Override
	public boolean isInterestedInSuccess() {
		
		return true;
	}

}